package com.youjia.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youjia.mapper.RightsMapper;
import com.youjia.pojo.Rights;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class RightsServiceImpl implements RightsService {
    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> getRightsList(Integer userId) {

        List<Rights> rightsList = rightsMapper.getRightsList(userId);
        log.info(rightsList.toString());
        for (Rights onelist : rightsList) {
            QueryWrapper<Rights> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("parent_id", onelist.getId());
            List<Rights> rights = rightsMapper.selectList(queryWrapper);
            log.info(rights.toString());
            onelist.setChildren(rights);
        }
        return rightsList;
    }
}
